package bpm.dao.impl.document;

import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import bpm.domain.document.AttachmentType;
import bpm.domain.document.AttachmentType.AttachmentTypeKey;
import bpm.domain.document.AttachmentType.PaperyType;
import bpm.domain.document.AttachmentType.ReferenceType;
/**
 * 
 * @author ZhaoWangLong Aug 16, 2011
 *
 */
public class AttachmentTypeRowMapper implements RowMapper {
	private boolean reference=false;
	public AttachmentTypeRowMapper(){}
	public AttachmentTypeRowMapper(boolean reference){
		this.reference=reference;
	}
	public Object mapRow(ResultSet rs, int i) throws SQLException {
		AttachmentType attachType=new AttachmentType();
		attachType.setId(rs.getInt("ID"));
		AttachmentTypeKey typeKey=AttachmentTypeKey.valueOf(rs.getString("KEY"));
		attachType.setKey(typeKey);
		if(reference){
			attachType.setReference(ReferenceType.valueOf(rs.getString("REFERENCE")));
			attachType.setPapery(PaperyType.valueOf(rs.getString("PAPERY")));
		}
		attachType.setName(rs.getString("NAME"));
		attachType.setRank(rs.getInt("RANK"));
		attachType.setEnable("1".equals(rs.getString("ENABLE"))?true:false);
		attachType.setCreateTime(rs.getDate("CREATE_TIME"));
		attachType.setLastUpdateTime(rs.getDate("LAST_UPDATE_TIME"));
		attachType.setDescription(rs.getString("DESCRIPTION"));
		return attachType;
	}

}
